 $LOAD_PATH.unshift File.join(File.dirname(__FILE__),'../..','ext_pr1/lib')
 require 'ext_pr1_v4'
# Uhr vorstellen
# vorstellen_uhr ::= (stunde_alt, minute_alt, sekunde_alt, stunde_add, minute_add, sekunde_add, mode)::
#                        Nat x Nat x Nat x Int x Int x Int  -> Nat where (stunde_alt < 24 and stunde_alt > 0, minute_alt <= 60 and minute_alt > 0,
#                        sekunde_alt <= 60 and sekunde_alt > 0) 
#                                                           -> Int where (stunde_add < 24 and stunde_add > 0 , minute_add <= 60 and minute_add > 0,
#                        sekunde_add <= 60 and sekunde_add > 0 , mode = 12 or mode = 24)
# Test {(12, 0, 0, 1, 0, 0, 24)=>[13, 0, 0], (12, 0, 0, 1, 0, 0, 12)=>[1, 0, 0],
# (12, 0, 0, 0, 1, 0, 24)=>[12, 1, 0], (12, 0, 0, 0, 0, 1, 24)=>[12, 0, 1], 
# (12, 0, 0, 0, 1, 0, 12)=>[12, 1, 0], (12, 0, 0, 0, 0, 1, 12)=>[12, 0, 1],
# (12, 0, 0, 23, 0, 0, 24)=>[11, 0, 0], (12, 0, 0, 23, 0, 0, 12)=>[11, 0, 0], 
# (12, 59, 59, 0, 0, 1, 24)=>[13, 0, 0], (12, 59, 59, 0, 0, 1, 12)=>[1, 0, 0], 
# (12, 59, 0, 0, 1, 0, 24)=>[13, 0, 0], (12, 59, 0, 0, 1, 0, 12)=>[1, 0, 0], 
# (23, 59, 59, 0, 0, 1, 24)=>[0, 0, 0], (11, 59, 59, 0, 0, 1, 12)=>[0, 0, 0],
# (12, 0, 0, 25, 0, 0, 24)=>[13, 0, 0],(12, 0, 0, 25, 0, 0, 12)=>[1, 0, 0], 
# (12, 0, 0, 0, 90, 0, 24)=>[13, 30, 0], (12, 0, 0, 0, 90, 0, 24)=>[13, 30, 0], 
# (12, 0, 0, 0, 0, 90, 24)=>[12, 1, 30], (12, 0, 0, 0, 0, 90, 12)=>[12, 1, 30],
# (24, 59, 59, 0, 0, 1, 24)=>Err, (23, 60, 59, 0, 0, 1, 24)=>Err, 
# (23, 59, 60, 0, 0, 1, 24)=>Err, (-23, 0, 0, 0, 0, 1, 24)=>Err,(-11, 0, 0, 0, 0, 1, 12)=>Err, 
# (23, -59, 0, 0, 0, 1, 24)=>Err,(23, 0, -59, 0, 0, 1, 24)=>Err, (11, -59, 0, 0, 0, 1, 12)=>Err, 
# (11, 0, -59, 0, 0, 1, 12)=>Err, (23, 0, 0, 0, 0, 1, 12)=>Err, (23, 59, 59, 0, 0, "test", 24)=>Err, 
# (23, 59, 59, 0, "test", 0, 24)=>Err, (23, 59, 59, "test", 0, 0, 24)=>Err, 
# (23, 59, "test", 0, 0, 0,  24)=>Err, (23, "test", 59, 0, 0, 0,  24)=>Err, 
# ("test", 59, 59, 0, 0, 0,  24)=>Err, (23, 59, 59, 0, 0, 0,  "test")=>Err,
# (11, 59, 59, 0, 0, "test", 12)=>Err, (11, 59, 59, 0, "test", 0, 12)=>Err,
# (11, 59, 59, "test", 0, 0, 12)=>Err, (11, 59, "test", 0, 0, 0,  12)=>Err, 
# (11, "test", 59, 0, 0, 0,  12)=>Err, ("test", 59, 59, 0, 0, 0,  12)=>Err, 
# (23, 59, 59, 0, 0, 0,  "test")=>Err,
# (23.0, 59, 59, 0, 0, 0, 24)=>Err, (23, 59.0, 59, 0, 0, 0, 24)=>Err, 
# (23, 59, 59.0, 0, 0, 0, 24)=>Err, (23, 59, 59, 1.0, 0, 0, 24)=>Err, 
# (23, 59, 59, 0, 1.0, 0, 24)=>Err, (23, 59, 59, 0, 0, 1.0, 24)=>Err,
# (23, 59, 59, 0, 0, 0, 24.0)=>Err, (11.0, 59, 59, 0, 0, 0, 12)=>Err, 
# (11, 59.0, 59, 0, 0, 0, 12)=>Err, (11, 59, 59.0, 0, 0, 0, 12)=>Err, 
# (11, 59, 59, 1.0, 0, 0, 12)=>Err, (11, 59, 59, 0, 1.0, 0, 12)=>Err, 
# (11, 59, 59, 0, 0, 1.0, 12)=>Err, (11, 59, 59, 0, 0, 0, 12.0)=>Err 

  MIN_IN_SEC = 60
  MIN_IN_HOUR = 60
  HOURS_PER_DAY = 24
  MODE24 = HOURS_PER_DAY
  MODE12 = (HOURS_PER_DAY)/2

  
  def vorstellen_uhr(stunde_alt, minute_alt, sekunde_alt, stunde_add, minute_add, sekunde_add, mode)
    check_pre((
        stunde_alt.nat? and minute_alt.nat? and sekunde_alt.nat? and 
        stunde_add.int? and minute_add.int? and sekunde_add.int? and mode.nat? and ((mode == MODE24)or (mode == MODE12))and
      (mode == MODE24 ? stunde_alt < MODE24 : stunde_alt <= MODE12) and minute_alt < MIN_IN_HOUR and sekunde_alt < MIN_IN_SEC))
    
    minute_carry, sekunde_temp  = (sekunde_alt+sekunde_add).divmod(MIN_IN_SEC) 
    stunde_carry, minute_temp = (minute_alt + minute_add + minute_carry).divmod(MIN_IN_HOUR) 
    stunde_temp = (stunde_alt + stunde_add + stunde_carry)
    stunde_temp = (mode == MODE24 ? stunde_temp >= mode : stunde_temp > mode) ? stunde_temp.divmod(mode)[1] : stunde_temp
    [stunde_temp,minute_temp,sekunde_temp]
      
 
    end